<!--
 * @Author       : xiaowu wwl093000@163.com
 * @Date         : 2023-04-20 10:26:36
 * @LastEditTime : 2023-05-06 15:43:48
 * @LastEditors  : xiaowu wwl093000@163.com
 * @FilePath     : /erp-admin-ui/src/views/workorder/details/index.vue
 * @Description  : -
-->
<template>
  <div class="app-container input-class">
    <el-steps :active="detailInfo.status" simple>
      <el-step title="待处理"></el-step>
      <el-step title="处理中"></el-step>
      <el-step title="处理完成"></el-step>
    </el-steps>
    <div class="formBox" v-loading="loading">
      <div v-if="detailInfo.status == 0" class="formBox-item">
        <div class="card-wrapper">
          <div class="card-wrapper-content padding20">
            <div class="content-item flexbetween">
              <div class="content-status">{{ detailInfo.status == 0 ? '待处理' :  detailInfo.status == 1 ? '处理中' : '处理完成' }}</div>
              <el-button type="primary" @click="resolution">确认解决</el-button>
            </div>
            <div class="content-item">
              <div class="content-title">问题标题：</div>
              <div class="content-article">{{ detailInfo.subject }}</div>
            </div>
            <div class="content-item">
              <div class="content-title">问题描述：</div>
              <div class="content-article" v-html="detailInfo.content"></div>
            </div>
            <div class="line"></div>
            <div class="content-item flexbetween">
              <div class="item-left">
                <div class="item-left-i">工单编号：<span>{{ detailInfo.id }}</span></div>
                <div class="item-left-i">提交时间：<span>{{ detailInfo.createTime }}</span></div>
              </div>
              <div class="item-right">
                <div class="item-button" @click="openBtn">追加问题</div>
              </div>
            </div>
          </div>
        </div>
        <div class="card-wrapper">
          <div class="card-wrapper-header">沟通记录</div>
          <div class="card-wrapper-content">
            <div class="content-list">
              <div
                v-for="(item, index) in detailInfo.recordsList"
                :key="index"
                class="list-item"
              >
                <div
                  class="list-item-avatar">
                  <el-avatar
                    :src="item.avatar ? item.avatar : 'https://cube.elemecdn.com/3/7c/3ea6beec64369c2642b92c6726f1epng.png'">
                  </el-avatar>
                </div>
                <div class="list-item-main">
                  <div class="list-item-main-info"><span>tb：{{ item.nickName }}</span><span>{{ item.createTime }}</span></div>
                  <div class="list-item-main-content" v-html="item.chat"></div>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
      <div v-if="detailInfo.status == 1" class="formBox-item">
        <div class="card-wrapper">
          <div class="card-wrapper-content padding20">
            <div class="content-item flexbetween">
              <div class="content-status">{{ detailInfo.status == 0 ? '待处理' :  detailInfo.status == 1 ? '处理中' : '处理完成' }}</div>
              <el-button type="primary" @click="resolution">确认解决</el-button>
            </div>
            <div class="content-item">
              <div class="content-title">问题标题：</div>
              <div class="content-article">{{ detailInfo.subject }}</div>
            </div>
            <div class="content-item">
              <div class="content-title">问题描述：</div>
              <div class="content-article" v-html="detailInfo.content"></div>
            </div>
            <div class="line"></div>
            <div class="content-item flexbetween">
              <div class="item-left">
                <div class="item-left-i">工单编号：<span>{{ detailInfo.id }}</span></div>
                <div class="item-left-i">提交时间：<span>{{ detailInfo.createTime }}</span></div>
              </div>
              <div class="item-right">
                <div class="item-button" @click="openBtn">追加问题</div>
              </div>
            </div>
          </div>
        </div>
        <div class="card-wrapper">
          <div class="card-wrapper-header">沟通记录</div>
          <div class="card-wrapper-content">
            <div class="content-list">
              <div
                v-for="(item, index) in detailInfo.recordsList"
                :key="index"
                class="list-item"
              >
                <div
                  class="list-item-avatar">
                  <el-avatar
                    :src="item.avatar ? item.avatar : 'https://cube.elemecdn.com/3/7c/3ea6beec64369c2642b92c6726f1epng.png'">
                  </el-avatar>
                </div>
                <div class="list-item-main">
                  <div class="list-item-main-info"><span>tb：{{ item.nickName }}</span><span>{{ item.createTime }}</span></div>
                  <div class="list-item-main-content" v-html="item.chat"></div>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
      <div v-if="detailInfo.status == 2" class="formBox-item">
        <div class="card-wrapper">
          <div class="card-wrapper-content padding20">
            <div class="content-item flexbetween">
              <div class="content-status">{{ detailInfo.status == 0 ? '待处理' :  detailInfo.status == 1 ? '处理中' : '处理完成' }}</div>
            </div>
            <div class="content-item">
              <div class="content-title">问题标题：</div>
              <div class="content-article">{{ detailInfo.subject }}</div>
            </div>
            <div class="content-item">
              <div class="content-title">问题描述：</div>
              <div class="content-article" v-html="detailInfo.content"></div>
            </div>
            <div class="line"></div>
            <div class="content-item flexbetween">
              <div class="item-left">
                <div class="item-left-i">工单编号：<span>{{ detailInfo.id }}</span></div>
                <div class="item-left-i">提交时间：<span>{{ detailInfo.createTime }}</span></div>
              </div>
            </div>
          </div>
        </div>
        <div class="card-wrapper">
          <div class="card-wrapper-header">沟通记录</div>
          <div class="card-wrapper-content">
            <div class="content-list">
              <div
                v-for="(item, index) in detailInfo.recordsList"
                :key="index"
                class="list-item"
              >
                <div
                  class="list-item-avatar">
                  <el-avatar
                    :src="item.avatar ? item.avatar : 'https://cube.elemecdn.com/3/7c/3ea6beec64369c2642b92c6726f1epng.png'">
                  </el-avatar>
                </div>
                <div class="list-item-main">
                  <div class="list-item-main-info"><span>tb：{{ item.nickName }}</span><span>{{ item.createTime }}</span></div>
                  <div class="list-item-main-content" v-html="item.chat"></div>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
      <div v-if="detailInfo.status == 3" class="formBox-item">
        <div class="card-wrapper">
          <div class="card-wrapper-header">评价</div>
          <div class="card-wrapper-content">

          </div>
        </div>
        <div class="card-wrapper">
          <div class="card-wrapper-content padding20">
            <div class="content-item flexbetween">
              <div class="content-status">已完结</div>
              <!-- <el-button type="primary">确认受理</el-button> -->
            </div>
            <div class="content-item">
              <div class="content-title">问题标题：</div>
              <div class="content-article">容器服务正常启动，但端口访问被拒绝</div>
            </div>
            <div class="line"></div>
            <div class="content-item flexbetween">
              <div class="item-left">
                <div class="item-left-i">工单编号：<span>685421</span></div>
                <div class="item-left-i">提交时间：<span>2023-04-15</span></div>
              </div>
              <div class="item-right">
                <!-- <div class="item-button">追加问题</div> -->
              </div>
            </div>
          </div>
        </div>
        <div class="card-wrapper">
          <div class="card-wrapper-header">沟通记录</div>
          <div class="card-wrapper-content">
            <div class="content-list">
              <div class="list-item">
                <div class="list-item-avatar"><el-avatar
                    src="https://cube.elemecdn.com/3/7c/3ea6beec64369c2642b92c6726f1epng.png"></el-avatar></div>
                <div class="list-item-main">
                  <div class="list-item-main-info"><span>tb：15454455</span><span>2023-04-23</span></div>
                  <div class="list-item-main-content">

                  </div>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
    <!-- 沟通记录 -->
    <el-dialog title="追加问题" :visible.sync="open" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="100px">
        <el-form-item label="问题描述" prop="chat">
          <Editor :disabled="buttonLoading" v-model="form.chat" :min-height="192"></Editor>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button :disabled="buttonLoading" :loading="buttonLoading" type="primary" @click="submitForm">确 定</el-button>
        <el-button :disabled="buttonLoading" @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { getWorkOrderDetails, addWorkRecords, confirmSolve } from "@/api/workorder/index";
export default {
  data() {
    return {
      // 遮罩层
      loading: false,
      list: [],
      form: {},
      rules: {
        chat: [
          { required: true, trigger: "blur", message: "必填项不能为空" }
        ]
      },
      buttonLoading: false,
      tabsValue: '0',
      active: 0,
      detailInfo: {},
      open: false
    };
  },
  created() {
    this.getInfo(this.$route.params.id);
  },
  methods: {
    /** 查询产品详情 */
    getInfo(id) {
      this.loading = true;
      getWorkOrderDetails(id).then(res => {
        this.detailInfo = res.data;
        this.form.workId = res.data.id;
        this.loading = false;
      });
    },
    // 确认解决
    resolution() {
      this.$confirm('确认问题已解决完成了吗?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        confirmSolve({id: this.form.workId}).then(res => {
          this.getInfo(this.$route.params.id);
        }).finally(() => {
          this.getInfo(this.$route.params.id);
        });
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消确认'
        });          
      });
    },
    // 追加问题弹框
    openBtn() {
      this.open = true;
    },
    // 追加问题
    submitForm() {
      this.$refs["form"].validate((valid, obj) => {
        if (valid) {
          this.buttonLoading = true;
          addWorkRecords(this.form).then(res => {
            this.$modal.msgSuccess("提交成功");
            this.getInfo(this.$route.params.id);
            this.cancel();
          }).finally(() => {
            this.buttonLoading = false;
            this.getInfo(this.$route.params.id);
          });
        } else {
          var a = [];
          for (let key in obj) {
            a.push(obj[key][0].message);
          }
          this.$message({
            message: a[0],
            type: "warning",
          });
          return false;
        }
      })
    },
    cancel() {
      this.open = false;
      this.form.chat = '';
    }
  }
};
</script>

<style lang="scss">
.input-class {

  .el-form-item {
    margin: 22px 0;
  }

  .button-box {
    width: 100%;
    display: flex;
    justify-content: center;
    margin-top: 40px;
  }

  .itemFlex {
    width: 100%;
    display: flex !important;

    .el-select {
      width: 50%;
    }

    .el-form-item__content {
      flex: 1;
    }

    .inputWidth10 {
      width: 10%;
      margin: 0 10px;
    }
  }

  .card-wrapper {
    border: 1px solid #DCDFE6;
    margin: 20px 0;

    .card-wrapper-header {
      background-color: #F5F7FA;
      border-bottom: 1px solid #dfe4ed;
      font-size: 20px;
      color: #909399;
      line-height: 40px;
      padding: 0 15px;
      font-weight: 500;
    }

    .card-wrapper-content {
      padding: 15px 20px 30px;

      .content-item {
        .content-status {
          font-size: 16px;
          color: #666666;
          line-height: 30px;
        }

        .content-title {
          font-size: 14px;
          line-height: 18px;
          color: #666666;
          margin: 15px 0;
        }

        .content-article {
          font-size: 14px;
          line-height: 20px;
          color: #000;
        }

        .item-left {
          display: flex;
          align-items: center;

          .item-left-i {
            margin-right: 30px;
            font-size: 14px;
            line-height: 20px;
            color: #666666;

            span {
              color: #000;
            }

            &:last-child {
              margin-right: 0;
            }
          }
        }

        .item-right {
          .item-button {
            padding: 0 15px;
            line-height: 30px;
            cursor: pointer;
            font-size: 14px;
            color: #409EFF;
          }
        }
      }

      .content-list {
        .list-item {
          display: flex;
          align-items: flex-start;
          padding-bottom: 15px;
          padding-top: 15px;
          border-bottom: 1px dashed #dfe4ed;

          &:last-child {
            border-bottom: none;
          }

          .list-item-main {
            flex: 1;
            padding: 0 20px;

            .list-item-main-info {
              span {
                font-size: 14px;
                line-height: 20px;
                color: #666666;
                margin-right: 15px;
              }
            }

            .list-item-main-content {
              margin: 10px 0 0;
              font-size: 14px;
              line-height: 20px;
              color: #000;
            }
          }
        }
      }

      .line {
        width: 100%;
        height: 1px;
        background: #dfe4ed;
        margin: 15px 0;
      }

      .flexbetween {
        display: flex;
        align-items: center;
        justify-content: space-between;
      }
    }

    .padding20 {
      padding: 20px;
    }

    .button-box {
      padding-left: 300px;
      margin-top: 15px;
      display: flex;
      align-items: center;
    }
  }
}
</style>